//
//  CommandLineAppLauncherTest.swift
//  SwiftTools
//
//  Created by Samuel Richard Magny on 15-10-04.
//  Copyright © 2015 Samuel Richard Magny. All rights reserved.
//

import XCTest
import SwiftTools

class CommandLineAppLauncherTest: XCTestCase {

    let echoMessage1 = "Hello"
    var currentExpectation:XCTestExpectation? = nil
    
    override func setUp() {
        super.setUp()

    }
    
    override func tearDown() {

        super.tearDown()
    }

    func testLaunchingIOApp() {
        currentExpectation = self.expectationWithDescription("launcher should have output")
        
        let launcher = CommandLineAppLauncher(applicationPath: "/bin/echo", workingDirectory: "", outputBlock: outputBlock)
        launcher.args = [echoMessage1]
        
        launcher.launch()
        
        launcher.write(echoMessage1)
        
        
        self.waitForExpectationsWithTimeout(1.0) { (error) -> Void in
            if (error != nil){
                print("Timeout error: " + (error?.description)!)
            }
        }
    }

    
    private func outputBlock(dataString:String) -> Bool
    {
        XCTAssertEqual(dataString, echoMessage1 + "\n")
        currentExpectation?.fulfill()
        return true
    }

}
